<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>明少帥小程序管理后台</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/bootstrap.min.css">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/font-awesome.min.css">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="${request.contextPath}/statics/css/all-skins.min.css">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/main.css">
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body class="hold-transition login-page">
<div class="login-box" id="rrapp" v-cloak>
  <div class="login-logo">
    <b>明少帥小程序管理后台</b>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body" id="login">
      <p class="login-box-msg">管理员登录</p>
      <div v-if="error" class="alert alert-danger alert-dismissible">
        <h4 style="margin-bottom: 0px;"><i class="fa fa-exclamation-triangle"></i> {{errorMsg}}</h4>
      </div>
      <div class="form-group has-feedback">
        <input type="text" class="form-control" v-model="username" placeholder="账号">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" class="form-control" v-model="password" placeholder="密码">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="text" class="form-control" v-model="captcha" @keyup.enter="login" placeholder="验证码">
        <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <img alt="如果看不清楚，请单击图片刷新！" class="pointer" :src="src" @click="refreshCode">
        &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" @click="refreshCode">点击刷新</a>
      </div>
      
      
      <div class="row">
        <div class="col-xs-8">
            <p class="message" @click="create">还没有账户? <a href="#">立刻创建</a></p>
            <p class="message" @click="forgetF"><a href="#">忘记密码</a></p>
            <div class="checkbox icheck">
          </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-4">
          <button type="button" class="btn btn-primary btn-block btn-flat" @click="login">登录</button>
        </div>
        <!-- /.col -->
      </div>
    <!-- /.social-auth-links -->

  </div>

    <div class="login-box-body" id="register" style="display:none;">
        <p class="login-box-msg">管理员注册</p>
        <div v-if="errorR" class="alert alert-danger alert-dismissible">
            <h4 style="margin-bottom: 0px;"><i class="fa fa-exclamation-triangle"></i> {{errorMsgR}}</h4>
        </div>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" v-model="usernameR" placeholder="账号">
            <span class="glyphicon glyphicon-user form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="password" class="form-control" v-model="passwordR" placeholder="密码">
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="password" class="form-control" v-model="passwordRR" placeholder="确认密码">
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" v-model="email" placeholder="邮箱(用于找回密码)">
            <span class="glyphicon glyphicon-user form-control-feedback"></span>
        </div>
        <div class="row">
            <div class="col-xs-8">
                <p class="message" @click="loginR">已经有了一个账户? <a href="#">立刻登录</a></p>
                <div class="checkbox icheck">
                </div>
            </div>
            <!-- /.col -->
            <div class="col-xs-4">
                <button type="button" class="btn btn-primary btn-block btn-flat" @click="register">注册</button>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.social-auth-links -->

    </div>
    <div class="login-box-body" id="forget" style="display:none;">
        <p class="login-box-msg">管理员找回密码</p>
        <div v-if="errorF" class="alert alert-danger alert-dismissible">
            <h4 style="margin-bottom: 0px;"><i class="fa fa-exclamation-triangle"></i> {{errorMsgF}}</h4>
        </div>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" v-model="usernameF" placeholder="账号">
            <span class="glyphicon glyphicon-user form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="password" class="form-control" v-model="passwordF" placeholder="新密码">
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" style="width: 50%" v-model="code" placeholder="邮箱验证码">
            <!--<span class="glyphicon glyphicon-user form-control-feedback"></span>-->
            <button type="button" id="btn" class="btn btn-primary btn-block btn-flat" style="position: absolute;right: 0%;width: 39%;top: 0%;" @click="sendMail">获取验证码</button>
        </div>
        <div class="row">
            <div class="col-xs-8">
                <p class="message" @click="loginR">没有忘记? <a href="#">立刻登录</a></p>
                <div class="checkbox icheck">
                </div>
            </div>
            <!-- /.col -->
            <div class="col-xs-4">
                <button type="button" class="btn btn-primary btn-block btn-flat" @click="forget">确认</button>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.social-auth-links -->

    </div>
  <!-- /.login-box-body -->
</div>

<!-- /.login-box -->
<script src="${request.contextPath}/statics/libs/jquery.min.js"></script>
<script src="${request.contextPath}/statics/libs/vue.min.js"></script>
<script src="${request.contextPath}/statics/libs/bootstrap.min.js"></script>
<script src="${request.contextPath}/statics/libs/jquery.slimscroll.min.js"></script>
<script src="${request.contextPath}/statics/libs/fastclick.min.js"></script>
<script src="${request.contextPath}/statics/libs/app.js"></script>
<script type="text/javascript">
var vm = new Vue({
	el:'#rrapp',
	data:{
		username: '',
		password: '',
		captcha: '',
		error: false,
		errorMsg: '',
		src: 'captcha.jpg',
        usernameR: '',
        passwordR: '',
        captchaR: '',
        errorR: false,
        errorMsgR: '',
        passwordRR: '',
        errorF: false,
        errorMsgF: '',
        usernameF: '',
        email: '',
        passwordF:'',
        code:''
	},
	beforeCreate: function(){
		if(self != top){
			top.location.href = self.location.href;
		}
	},
	methods: {
		refreshCode: function(){
			this.src = "captcha.jpg?t=" + $.now();
		},
		login: function (event) {
			var data = "username="+vm.username+"&password="+vm.password+"&captcha="+vm.captcha;
			$.ajax({
				type: "POST",
			    url: "sys/login",
			    data: data,
			    dataType: "json",
			    success: function(result){
					if(result.code == 0){//登录成功
						parent.location.href ='index.html';
					}else{
						vm.error = true;
						vm.errorMsg = result.msg;
						
						vm.refreshCode();
					}
				}
			});
		},
        register: function (event) {
		    var username = vm.usernameR;
		    if (username == null || username==''){
                vm.errorR = true;
                vm.errorMsgR = "用户名不能为空";
                return;
            }
            var password = vm.passwordR;
            if (password == null || password==''){
                vm.errorR = true;
                vm.errorMsgR = "密码不能为空";
                return;
            }
            var passwordR = vm.passwordRR;
            if (password != passwordR){
                vm.errorR = true;
                vm.errorMsgR = "两次密码不一致";
                return;
            }
            var email = vm.email;
            if (email == null || email==''){
                vm.errorR = true;
                vm.errorMsgR = "邮箱不能为空";
                return;
            }
            //对电子邮件的验证
            var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            if(!myreg.test(email)){
                vm.errorR = true;
                vm.errorMsgR = "请输入有效的E_mail";
                return;
            }
            var data = "username="+username+"&password="+password+"&email="+email;
            $.ajax({
                type: "POST",
                url: "sys/register",
                data: data,
                dataType: "json",
                success: function(result){
                    if(result.code == 0){//注册成功
                        alert("注册成功,请前往登陆！")
                        parent.location.href ='login.html';
                    }else{
                        vm.errorR = true;
                        vm.errorMsgR = result.msg;
                    }
                }
            });
        },
        forget: function (event) {
            var username = vm.usernameF;
            if (username == null || username==''){
                vm.errorF = true;
                vm.errorMsgF = "用户名不能为空";
                return;
            }
            var password = vm.passwordF;
            if (password == null || password ==''){
                vm.errorF = true;
                vm.errorMsgF = "密码不能为空";
                return;
            }
            var code = vm.code;
            if (code == null || code ==''){
                vm.errorF = true;
                vm.errorMsgF = "验证码不能为空";
                return;
            }
            var data = "username="+username+"&password="+password+"&code="+code;
            $.ajax({
                type: "POST",
                url: "sys/forget",
                data: data,
                dataType: "json",
                success: function(result){
                    if(result.code == 0){//找回密码成功
                        alert("修改成功,请前往登陆！")
                        parent.location.href ='login.html';
                    }else{
                        vm.errorF = true;
                        vm.errorMsgF = result.msg;
                    }
                }
            });
        },
        sendMail:function () {
            var username = vm.usernameF;
            if (username == null || username==''){
                vm.errorF = true;
                vm.errorMsgF = "用户名不能为空";
                return;
            }
            var data = "username="+username;
            $.ajax({
                type: "POST",
                url: "mpq/sendMail",
                data: data,
                dataType: "json",
                success: function(result){
                    if(result.code == 0){//发送验证码成功
                        vm.invokeSettime("#btn");
                        alert("验证码已发送至您的邮箱,请前往邮箱查看验证码,5分钟之内有效！")
                    }else{
                        vm.errorF = true;
                        vm.errorMsgF = result.msg;
                    }
                }
            });
        },
        invokeSettime: function(obj){
            var countdown=60;
            settime(obj);
            function settime(obj) {
                if (countdown == 0) {
                    $(obj).attr("disabled",false);
                    $(obj).text("获取验证码");
                    countdown = 60;
                    return;
                } else {
                    $(obj).attr("disabled",true);
                    $(obj).text("(" + countdown + ") s 重新发送");
                    countdown--;
                }
                setTimeout(function() {
                        settime(obj) }
                    ,1000)
            }
        },
        create: function (event) {
            var introductionl =document.getElementById("login");
            var introduction =document.getElementById("register");
            var introduction2 =document.getElementById("forget");
                introduction.style.display = "block";
                introductionl.style.display = "none";
                introduction2.style.display = "none";
        },
        loginR: function (event) {
            var introductionl =document.getElementById("login");
            var introduction =document.getElementById("register");
            var introduction2 =document.getElementById("forget");
            introduction.style.display = "none";
            introductionl.style.display = "block";
            introduction2.style.display = "none";
        },
        forgetF: function (event) {
            var introductionl =document.getElementById("login");
            var introduction =document.getElementById("register");
            var introduction2 =document.getElementById("forget");
            introduction.style.display = "none";
            introductionl.style.display = "none";
            introduction2.style.display = "block";
        }
	}
});
</script>
</body>
</html>
